from celery_task.celery import app


@app.task
def update_banner():
    from home import models
    from django.conf import settings
    from home.serializer import BannerSerializer
    from django.core.cache import cache
    banners = models.Banner.objects.filter(is_delete=False, is_show=True).order_by('-orders')[:settings.BANNER_SIZE]
    ser = BannerSerializer(instance=banners, many=True)
    banner_data = ser.data

    for banner in banner_data:
        banner['img'] = 'http://127.0.0.1:8000%s' % banner['img']

    cache.set('banner_data', banner_data)

    return True
